package com.example.gulimall.common.exceptions;

import com.example.gulimall.common.utils.JsonResultVO;
import com.example.gulimall.common.utils.ResponseHelper;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <p>@description: 全局异常处理  </p>
 * <p>@author: JGD </p>
 * <p>@create: 2020/2/10 10:17 </p>
 * <p>@version : 2.0.0
 **/
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * apiException异常类捕捉
     *
     * @param c 异常信息
     * @return JsonResultVO
     */
    @ExceptionHandler(value = ApiException.class)
    @ResponseStatus(HttpStatus.OK)
    public <C extends ApiException> JsonResultVO catchApiException(C c) {
        return ResponseHelper.createJsonResult(c.getErrorCode(), c.getMessage(), c.getData());
    }

}
